<template>
  <div id="app">
    <div class="head">
      <p>天润商城后台管理系统</p>
    </div>
    <div class="login">
      <table border="0" cellspacing="20">
        <tr>
          <td>用户名：</td>
          <td>
            <el-input
              prefix-icon="iconfont icon-xingmingyonghumingnicheng"
              placeholder="请输入账号"
              v-model="account"
              clearable
            ></el-input>
          </td>
        </tr>

        <tr>
          <td>密码：</td>
          <td>
            <el-input
              prefix-icon="iconfont icon-mima"
              placeholder="请输入密码"
              v-model="password"
              show-password
            ></el-input>
          </td>
        </tr>
        <tr>
          <td colspan="2" style="text-align: center; padding-top: 50px">
            <el-button type="danger" style="width: 60%" @click="login"
              >登录</el-button
            >
          </td>
        </tr>
      </table>
    </div>
  </div>
</template>

<script>
import Header from "../components/header.vue";
export default {

  data() {
    return { account: "", password: "" };
  },
  methods: {
    success() {
      this.$notify({
        title: "成功",
        message: "登录成功！正在跳转！",
        type: "success",
      });
    },
    err() {
      this.$notify.error({
        title: "错误",
        message: "登录失败",
      });
    },
    login() {
      let that = this;
      this.$http
        .get(
          "FoodWeb/loginByPhoneAction.action",
          {
            params: {
              phone: this.account,
              verifycode: this.password,
            },
          },
          { dataType: "json" }
        )
        .then((res) => {
          console.log(res);
          var users = res.data.user;
          if (res.data.errorcode != 0) {
            that.err();
          } else {
            that.success();

            window.sessionStorage.setItem("user", JSON.stringify(users));
            setTimeout(() => {
              this.$router.push({
                path: "/article",
                query: { user: res.data.user },
              });
            }, 3000);
          }
        });
      console.log(this.account, this.password);
    },
  },
  components: {
    Header,
  },
};
</script>

<style lang="less" scoped>
.head {
  height: 150px;
  width: 100vw;
  background-image: url(../assets/banner.jpg);
  background-repeat: no-repeat;
  background-size: cover;
  p {
    font-size: 30px;
    color: white;
    line-height: 150px;
    margin-left: 50px;
  }
}
.bg-purple {
  background: #d3dce6;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.login {
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 400px;
  margin: 0px auto;
  border: 2px #f3f3f3 solid;
  padding: 100px;
}
</style>
